(function($) {
	$(function() {
		//购物车点击事件
		$(".car_").click(function(){
			window.location.href="shopping-car.html";
		})
		
		var 
			pro_Name=$('.title00'),
			pro_Price=$('.price0'),
			b_tn=$('.sh-shopping-cart'),
			i_mga=$('.jpz');
			
			b_tn.click(function(){
				
				
				setCookies('jpz',i_mga.attr('src'),10)
				setCookies('title00',pro_Name.html(),10)
				
				setCookies('price0',pro_Price.html(),10)
				setCookies('value00',$('#goodsNumberInput').val(),10)
				$("#pic-move").fadeIn("fast").animate({
					left:-20,top:-20
				},200,function(){
					//$("#pic-move").fadeOut("fast");
					$("#pic-move").hide().css({left:-220,top:-70})
					
					$(".car-num").html(getCookie("value00"));
					$(".shopping-car span").html(getCookie("value00"));
				})
			})
			if(getCookie('valu')){
			$(".car-num").html(getCookie('valu'));
		}
		
		//头部滚动
		var
			i = 0,
			aLi = $(".show-notice li"),
			aUl = $(".show-notice");

		setInterval(function(){
			i++;
			aUl.stop(true).animate({
				top:-i*aLi.eq(0).height()
			},500,function(){
				if(i >= aLi.length/2){
					i = 0;
					aUl.css("top","0");
				}
			})
		},3000);
			
			
			
		//二维码出现
		$(".show-app,.down-app").mouseenter(function() {
				$(".down-app").stop(true).slideDown("fast");
			}).mouseleave(function() {
				$(".down-app").stop(true).slideUp("fast");
			})
			//搜索框
		var searchIndex = -1;
		$(".txt").focus(function() {
				$(".goods").css("display", "none");
				$(".search-list").css("display", "block");
			}).blur(function() {
				$(".goods").css("display", "block");
				$(".txt").val("");

				$(".search-list").css("display", "none");
			}).keyup(function(ev) {
				var
					evn = ev || event,
					aLi = $(".search-list>li");
				$(".goods").css("display", "none");
				if(evn.keyCode === 38 || evn.keyCode === 40) {

					if(evn.keyCode === 38 && searchIndex > 0) {
						searchIndex--;
					} else if(evn.keyCode === 40 && searchIndex < aLi.length - 1) {
						searchIndex++;
					}
					$(".txt").val(aLi.removeClass("active").eq(searchIndex).addClass("active").data("key"));

				}
			}).bind("input propertychange", function() {
				var iText = $(this).val();
				if(iText) {
					$.ajax({
						url: 'https://suggest.taobao.com/sug?code=utf-8',
						data: {
							q: iText
						},
						jsonp: "callback",
						dataType: "jsonp",
						success: function(data) {
							var arr = data.result;
							var iHtml = "";
							for(var i in arr) {

								iHtml += '<li data-key="' + arr[i][0] + '"><a href="javascript:;">' + arr[i][0] + '</a></li>';
							};
							if(iHtml) {
								$(".search-list").css("display", "block").html(iHtml);
							} else {
								$(".search-list").css("display", "none");
							};
							searchIndex = -1;
						}
					})
				}
			})
			//头部购物车
		$(".shopping-car,.show-car").mouseenter(function() {
				$("#b-jiantou").css("display", "none");
				$("#t-jiantou").stop(true).fadeIn("fast");
				$(".show-car").stop(true).slideDown("fast");
			}).mouseleave(function() {
				$("#t-jiantou").stop(true).fadeOut("fast");
				$("#b-jiantou").css({
					display: "block",
					top: 0
				});
				$(".show-car").stop(true).slideUp("fast");
			})
			//下拉菜单
		$(".nav-right,.nav-list").mouseenter(function() {
				$("#x-jiantou").css("display", "none");
				$("#s-jiantou").stop(true).fadeIn("fast");
				$(".nav-list").stop(true).slideDown("fast");
			}).mouseleave(function() {
				$("#s-jiantou").stop(true).fadeOut("fast");
				$("#x-jiantou").css({
					display: "block",
					top: 0
				});
				$(".nav-list").stop(true).slideUp("fast");
			})
			//侧边栏

		var
			aDiv = $(".right_t .move-left").not($(".infomation")),
			bDiv = $(".right_t .change-clo").not($(".myself")),
			dDiv = $(".right_b .move-left").not($(".weichat_")),
			cDiv = $(".right_b .change-clo").not($(".weichat"));
		//console.log(aDiv)		
		//console.log(bDiv)
		bDiv.mouseenter(function() {
			aIndex = bDiv.index($(this));
			aDiv.eq(aIndex).stop(true).animate({
				right: 33,
			}, 200);
		}).mouseleave(function() {
			aDiv.eq(aIndex).stop(true).animate({
				right: -90,
			}, 20);
		});

		cDiv.mouseenter(function() {
			bIndex = cDiv.index($(this));
			dDiv.eq(bIndex).stop(true).animate({
				right: 33,
			}, 200);
		}).mouseleave(function() {
			dDiv.eq(bIndex).stop(true).animate({
				right: -90,
			}, 20);
		});

		$(".myself").mouseenter(function() {

			$(".infomation").stop(true).animate({
				right: 33,
			}, 200);
		}).mouseleave(function() {
			$(".infomation").stop(true).animate({
				right: -265,
			}, 20);
		});

		$(".weichat").mouseenter(function() {

			$(".weichat_").stop(true).animate({
				right: 33,
			}, 200);
		}).mouseleave(function() {
			$(".weichat_").stop(true, true).animate({
				right: -132,
			}, 20);
		});

		$(".close").click(function() {
			$(".infomation").css("right", "-265px");
		});

		$(".goback").click(function() {
			$("body").animate({
				scrollTop: 0,
			}, 100)
		});
		
	
	
	//更换登录以及注册里面的内容
		var
			aLogin=$('.login_btn'),
			aRegister=$('.register_btn'),
			aUsername=getCookie('text1'),
			aUserpsw=getCookie('text2');
			
			//console.log(aLogin.length);

		if(aUsername&&aUserpsw){
			aLogin.html('手机用户'+aUsername)
			aLogin.attr('href','javascript:;')
			aRegister.html('[退出]')
			aRegister.attr('href','login.html')

		}
		
		aRegister.click(function(){
			aLogin.html('登录')
			aRegister.html('注册')
		})
		
		
	});
})(jQuery);





//设置获取cookie
function setCookies(key,value,iDays){
	var day= new Date();
	day.setDate(day.getDate()+iDays);
	document.cookie= key+ "="+ value+";expires="+day+";path=/";
 }
 function getCookie(key){
    var str = document.cookie;  
	var arr = str.split("; ");
	for(var i=0;i<arr.length;i++){
	  var arr2= arr[i].split("=");  
	  if(key==arr2[0]){
	    return arr2[1]
	  }
	}
	return "";
 }
//删除Cookie
function removeCookie(key){
	setCookies(key,"1",-1);
}

		
				//左右控制运动函数封装
function startTvMove(obt,dist){
	obt.stop(true).animate({left:dist},800);
	
}	
					